<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" slot="detail" :rules="validatorRules" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-form-model-item label="指定用户" prop="userName">
          <j-select-multi-user v-model="model.userName" :multiple="false" :query-config="selectUserQueryConfig" @select="getSelect"/>
        </a-form-model-item>
        <a-form-model-item v-if="showFlowSubmitButton">
          <a-button @click="submitForm">提 交</a-button>
        </a-form-model-item>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
  import { lockDataForUser } from '@/api/warning/WarningData.js'
  export default {
    name: "TenantForm",
    data () {
      return {
        model: {},
        userId:'',
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          userName:[ { required: true, message: '请选择指定用户!' },]
        },
        // 选择用户查询条件配置
        selectUserQueryConfig: [
          {key: 'realname', label: '姓名', placeholder: '请输入姓名'},
          {key: 'phone', label: '电话', placeholder: '请输入电话'},
        ],
        getSelectKeyDatas: []
      }
    },
    computed: {
      formDisabled(){
        if(this.normal===false){
          if(this.formData.disabled===false){
            return false
          }else{
            return true
          }
        }
        return this.disabled
      },
      disabledId(){
        return this.id?true : false;
      },
      showFlowSubmitButton(){
        if(this.normal===false){
          if(this.formData.disabled===false){
            return true
          }else{
            return false
          }
        }else{
          return false
        }
      }
    },
    methods: {
      show (record) {
        this.model = record?Object.assign({}, record):this.model;
        this.visible = true;
      },
      getSelect(record) {
        this.userId = record&& record.length>0? record[0].id :''
      },
      submitForm () {
        const parameter = {
          userId: this.userId,
          warningEvtids: this.getSelectKeyDatas
        }
        lockDataForUser(parameter)
          .then((res) => {
            if (res.success) {
              this.$message.success(res.message)
              this.$emit('ok');
            } else {
              this.$message.warn(res.message)
            }
          })
          .catch((e) => {
            this.$message.warn('请求失败！')
          })
      }
    }
  }
</script>
